package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Exam;
import cn.wolfcode.domain.ExamQuestion;
import cn.wolfcode.domain.Question;
import cn.wolfcode.domain.QuestionItem;
import cn.wolfcode.mapper.ExamMapper;
import cn.wolfcode.mapper.ExamQuestionMapper;
import cn.wolfcode.mapper.QuestionItemMapper;
import cn.wolfcode.mapper.QuestionMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IExamService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements IExamService {

    @Autowired
    private ExamMapper examMapper;

    @Autowired
    private QuestionMapper questionMapper;

    @Autowired
    private ExamQuestionMapper examQuestionMapper;

    @Autowired
    private QuestionItemMapper questionItemMapper;

    @Override
    public void save(Exam exam) {
        examMapper.insert(exam);
    }

    @Override
    public void delete(Long id) {
        examMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Exam exam) {
        examMapper.updateByPrimaryKey(exam);
    }

    @Override
    public Exam get(Long id) {
        return examMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Exam> listAll() {
        return examMapper.selectAll();
    }

    @Override
    public PageInfo<Exam> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Exam> exams = examMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Exam>(exams);
    }

    public List<Question> getList(Integer typeId){
        return questionMapper.selectByType(typeId);
    }

    @Override
    public void insert(ExamQuestion examQuestion) {
       examQuestionMapper.insert(examQuestion);
    }

    public List<Question> getQuestion(Long id,Integer typeId){
       return  questionMapper.getQuestion(id,typeId);
    }

    @Override
    public ExamQuestion getCount(Long id, Integer typeId) {
        return examQuestionMapper.getCount(id,typeId);
    }


}
